//模块化方案 import export default
// commonjs require module.exports exports
// 复用
module.exports = function(playerAction) {
    if(['rock','paper','scissor'].indexOf(playerAction) == -1) {
       throw new Error('invalid playerAction')
    } else {
        var computerAction;
        var random = Math.random() * 3
        if(random < 1) {
            computerAction = 'rock';
            console.log('电脑出了石头')
        } else if(random > 2) {
            computerAction = 'scissor';
            console.log('电脑出了剪刀')
        } else {
            computerAction = 'paper';
            console.log('电脑出了布')
        }
        
        if (computerAction === playerAction) {
            console.log("玩家出" + playerAction)
            console.log("平局");
        } else if (
            (computerAction == "rock" && playerAction == "paper") ||
            (computerAction == "scissor" && playerAction == "rock") ||
            (computerAction == "paper" && playerAction == "scissor")
        ) {
            // console.log("玩家出" + playerAction)
            console.log("玩家赢了")
            return 1
        } else {
            // console.log("玩家出" + playerAction)
            console.log("电脑赢了")
            return -1
        }
        
    }
}